package config

import (
	"fmt"
	"gin-service/utils"
	"os"
)

type MysqlStruct struct {
	Url string			`json:"url"`
	Username string		`json:"username"`
	Password string		`json:"password"`
	Database string		`json:"database"`
	Charset string		`json:"charset"`
	ParseTime string	`json:"parseTime"`
	Loc string			`json:"loc"`
}

type DevStruct struct {
	Mysql MysqlStruct		`json:"mysql"`
}

type TestStruct struct {
	Mysql MysqlStruct		`json:"mysql"`
}

type UatStruct struct {
	Mysql MysqlStruct		`json:"mysql"`
}

type ProdStruct struct {
	Mysql MysqlStruct		`json:"mysql"`
}

type JsonConfig struct {
	Development DevStruct	`json:"development"`
	Test TestStruct			`json:"test"`
	Uat UatStruct			`json:"uat"`
	Production ProdStruct	`json:"production"`
}

var GlobalRunningEnv string

func GetConfig() map[string]interface{} {
	var configJsonData JsonConfig
	utils.ParseJsonFile("config/config.json", &configJsonData)

	var configMapData map[string]interface{}
	utils.ParseJsonFile("config/config.json", &configMapData)

	envKey := configMapData["env_key"].(string)
	GlobalRunningEnv = os.Getenv(envKey)
	fmt.Printf("%s: %s\n", envKey, GlobalRunningEnv)

	envConfigData := configMapData[GlobalRunningEnv].(map[string]interface{})
	fmt.Printf("envConfigData: %+v\n", envConfigData)

	return envConfigData
}